<%--
  Created by IntelliJ IDEA.
  User: a
  Date: 2025/8/29
  Time: 10:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {

            //1.执行人 失去焦点 触发非空验证：
            $("[name='executor']").blur(ckexecutor);

            //2.任务描述 失去焦点 触发非空验证；
            $("[name='description']").blur(ckdescription);

            //3.点击 提交 按钮 发送异步请求：
            $("[value='提交']").click(function () {
                if(ckexecutor() && ckdescription()){

                    var executor=$("[name='executor']").val();
                    var description=$("[name='description']").val();
                    var orderlevel=$("[name='orderlevel']").val();
                    var pid=$("#hid").val();
                    $.get("wo/add",
                        {
                            "executor":executor,
                            "description":description,
                            "orderlevel":orderlevel,
                            "pid":pid
                        },
                        function (boo) {
                            JSON.stringify(boo);
                            if(boo){
                                alert("工单添加成功");
                                window.location.href="woList.jsp";
                            }else{
                                alert("工单添加失败！");
                            }
                    });
                }
            });
        });

        function ckexecutor() {
            var val=$("[name='executor']").val();
            if(val.length==0){
                alert("执行人不能为空");
                return false;
            }
            return true;
        }

        function ckdescription() {
            var val=$("[name='description']").val();
            if(val.length==0){
                alert("任务描述不能为空");
                return false;
            }
            return true;
        }



    </script>
</head>
<body>
    <table>
        <caption>添加工单</caption>
        <tr>
            <td>执行人*</td>
            <td>
                <input type="text" name="executor"/>
            </td>
        </tr>
        <tr>
            <td>任务描述*</td>
            <td>
                <input type="text" name="description"/>
            </td>
        </tr>
        <tr>
            <td>级别*</td>
            <td>
                <select name="orderlevel">
                    <option value="1">1级</option>
                    <option value="2">2级</option>
                    <option value="3">3级</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" value="提交"/>
            </td>
        </tr>
        <input type="hidden" id="hid" value="<%=request.getParameter("pid")%>"/>
    </table>
</body>
</html>
